Repository navigation
perf(buy-modal): derive oracle key with useMemo instead of effect + state (#543) - #632
Merged
nonsobethel0-dev merged 2 commits intoSep 23, 2026
Conversation
BuyPolicyModal synced the oracle key into state from a useEffect, so every keystroke in the lat/lng/year/month/flight fields rendered twice (input change, then setOracleKey) and the first render showed a stale key. Compute the key during render with useMemo from the builder inputs. Only categories without a key builder (disaster, health, ...) keep state, now named manualOracleKey, for the free-text input. Closes Parashield-Protocol#543
Assert the computed key updates as crop latitude and flight number are typed, and that manual oracle-key entry still works for categories without a builder. Refs Parashield-Protocol#543
|
@presidojay1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
❌ Deploy Preview for boisterous-sunshine-dd4c4c failed.
|
nonsobethel0-dev
merged commit Sep 23, 2026
e9959a1
into
Parashield-Protocol:main
0 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BuyPolicyModalcopied the oracle key into state from auseEffect:This caused two problems:
setOracleKey.Fix
This follows the approach suggested in the issue:
oracleKeyis now computed during render withuseMemo, fromproduct.categoryand the builder inputs, so there's no effect and no extra render.manualOracleKey, anduseMemoreturns it for those categories.invokeBuyPolicy/buyPolicyall still readoracleKey.Tests
Added in
src/__tests__/BuyPolicyModal.test.tsx:rainfall:1.5…)flight:KQ100:…)healthproductThe 7 failures already happen on
main, before this change. All of them are the existingrenderToStaticMarkuptests.Modalrenders nothing on the server, so the markup comes back as''.purchase-flow.integration.test.tsx > shows validation error for empty coveragealso fails onmain. With this PR the set of failing tests is exactly the same as onmain. Those tests are out of scope here and should be fixed separately.tsc --noEmitreports no new errors inBuyPolicyModal.tsx. The existingmakeProducttype error in the test file was already there.Closes #543
Closes #540
Closes #541
Closes #542